package com.glp.work.flow.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Service;

/**
 * @Auther: ywguo
 * @Date: 2020/7/31 16:13
 * @Description: aop日志拦截
 */
@Aspect
@Slf4j
@Service
public class PrintInterfaceTimeAspect {


    private static ThreadLocal<Long> thread = new ThreadLocal<>();

    public PrintInterfaceTimeAspect() {
    }

    //路径就自己定义咯
    @Pointcut(value = "execution(public * com.glp.work.flow.service.client..*.*(..))")
    public void feignInterfacePointCut() {
    }

    @Around(value = "feignInterfacePointCut()")
    public Object aroundFeignInterfaceMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        thread.set(start);
        Object obj = null;
        try {
            obj = joinPoint.proceed();
        } finally {
            log.info("调用关联方的方法及耗时 method = {} timeConsuming = {} 毫秒",
                    joinPoint.getSignature().getName(), System.currentTimeMillis() - start);
        }
        return obj;
    }






}

